package com.springmq.mq.juc;

import java.util.concurrent.*;

/**
 * @ClassName : Demo3
 * @Author : lby
 * @Date: 2021/2/4 14:01
 * @Description :
 */
public class Demo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadFactory threadFactory = r -> new Thread(r, "aaaaa" + r.hashCode());
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 10, TimeUnit.MINUTES, new SynchronousQueue<Runnable>(), threadFactory);
        Demo3Test demo3Test = new Demo3Test();
        // 当使用callable 创建线程时，不能直接使用线程对象，需要futureTask来中间代理
        FutureTask<String> futureTask = new FutureTask<String>(demo3Test);
        new Thread(futureTask).start();
        // 返回结果可以通过futureTask对象获取
        String s = futureTask.get();
//        executor.execute(()->{
//            demo3Test;
//        },"AAA");

    }


}

class Demo3Test implements Callable<String> {
    @Override
    public String call() throws Exception {
        return "123456";
    }
}
